
    import java.util.*;

    public class Solution {
        public boolean IsPopOrder(int [] pushA,int [] popA) {


            if(pushA.length == 0 || popA.length == 0 ) {
                return false;
            }

            Stack<Integer> stack = new Stack<>();
            int j = 0;//遍历popA数组

            for(int i = 0;i < pushA.length;i++) {
                int val = pushA[i];
                stack.push(val);

                while(!stack.empty() && j < popA.length &&  stack.peek() == popA[j]) {
                    stack.pop();
                    j++;
                }
            }
            return stack.empty();
        }
    }


